<?php

declare(strict_types=1);

namespace app\validate\user;

use think\Validate;

class ProfileValidate extends Validate
{
    protected $rule = [
        'nickname' => 'max:50',
        'real_name' => 'max:50',
        'email' => 'email',
        'avatar' => 'max:255',
        'current_password' => 'require|min:6',
        'new_password' => 'require|min:6|different:current_password',
        'confirm_password' => 'require|confirm:new_password',
        'contact' => 'array',
        'contact.contact_name' => 'max:50',
        'contact.contact_phone' => 'max:20',
        'contact.contact_email' => 'email',
        'contact.bank_name' => 'max:150',
        'contact.bank_account' => 'max:64',
        'contact.bank_account_name' => 'max:150',
        'contact.invoice_title' => 'max:150',
        'contact.invoice_taxno' => 'max:64',
        'shipping_address' => 'array',
        'shipping_address.contact_name' => 'max:50',
        'shipping_address.contact_phone' => 'max:20',
        'shipping_address.province' => 'max:50',
        'shipping_address.city' => 'max:50',
        'shipping_address.district' => 'max:50',
        'shipping_address.address' => 'max:255',
        'shipping_address.postal_code' => 'max:20',
        'receiving_address' => 'array',
        'receiving_address.contact_name' => 'max:50',
        'receiving_address.contact_phone' => 'max:20',
        'receiving_address.province' => 'max:50',
        'receiving_address.city' => 'max:50',
        'receiving_address.district' => 'max:50',
        'receiving_address.address' => 'max:255',
        'receiving_address.postal_code' => 'max:20',
    ];

    protected $message = [
        'nickname.max' => '昵称长度不能超过 50 个字符',
        'real_name.max' => '姓名长度不能超过 50 个字符',
        'email.email' => '邮箱格式不正确',
        'avatar.max' => '头像地址过长',
        'current_password.require' => '请输入当前密码',
        'current_password.min' => '当前密码长度至少 6 位',
        'new_password.require' => '请输入新密码',
        'new_password.min' => '新密码长度至少 6 位',
        'new_password.different' => '新密码不能与当前密码相同',
        'confirm_password.require' => '请确认新密码',
        'confirm_password.confirm' => '两次输入的密码不一致',
        'contact.array' => '联系信息格式不正确',
        'contact.contact_email.email' => '联系邮箱格式不正确',
        'shipping_address.array' => '发货地址格式不正确',
        'receiving_address.array' => '收货地址格式不正确',
    ];

    protected $scene = [
        'updateProfile' => ['nickname', 'real_name', 'email', 'avatar'],
        'updatePassword' => ['current_password', 'new_password', 'confirm_password'],
        'updateOrg' => [
            'contact',
            'contact.contact_name',
            'contact.contact_phone',
            'contact.contact_email',
            'contact.bank_name',
            'contact.bank_account',
            'contact.bank_account_name',
            'contact.invoice_title',
            'contact.invoice_taxno',
            'shipping_address',
            'shipping_address.contact_name',
            'shipping_address.contact_phone',
            'shipping_address.province',
            'shipping_address.city',
            'shipping_address.district',
            'shipping_address.address',
            'shipping_address.postal_code',
            'receiving_address',
            'receiving_address.contact_name',
            'receiving_address.contact_phone',
            'receiving_address.province',
            'receiving_address.city',
            'receiving_address.district',
            'receiving_address.address',
            'receiving_address.postal_code',
        ],
    ];

    protected function sceneUpdateProfile(): self
    {
        return $this->only($this->scene['updateProfile']);
    }

    protected function sceneUpdatePassword(): self
    {
        return $this->only($this->scene['updatePassword']);
    }

    protected function sceneUpdateOrg(): self
    {
        return $this->only($this->scene['updateOrg']);
    }
}
